<?php

namespace App\Validator\Admin\Common;

use App\Validator\BaseValidator;

class CategoryValidator extends BaseValidator
{

    protected array $attr = [
        'id' => '配置id',
        'ids' => '配置id',
        'code' => '唯一标识',
        'name' => '配置名称',
        'pid' => '上级id',
        'sort' => '分组显示的排序值',
        'cover' => '图片',
    ];

    public function add($data)
    {
        return $this->validate($data,[
            'code' => ['required_if:pid,0',],
            'name' => ['required','string',],
            'pid' => ['required','integer','min:0',],
            'sort' => ['required','integer','min:0',],
            'cover' => ['nullable','url',],
        ]);
    }

    public function detail($data)
    {
        return $this->validate($data,[
            'id' => ['required','integer','min:1'],
        ]);
    }

    public function update($data)
    {
        return $this->validate($data,[
            'id' => ['required','integer','min:1'],
            'code' => ['required_if:pid,0',],
            'name' => ['required','string',],
            'pid' => ['required','integer','min:0',],
            'sort' => ['required','integer','min:0',],
            'cover' => ['nullable','url',],
        ]);
    }

    public function del($data)
    {
        return $this->validate($data,[
            'ids' => ['required','array','min:1'],
            'ids.*' => ['required','integer','min:1'],
        ]);
    }


}
